﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace VirtualTournaments.Frontend
{
    [Themeable(true)]
    public partial class MenuViews : System.Web.UI.UserControl
    {
        //TODO: fin another way to do this
        public const int MainMenuIndex = 0;
        public const int TournamentSubscriptionMenuIndex = 1;
        public const int TournamentManagerMenuIndex = 2;
        public const int GamblingManagerMenuIndex = 3;
        public const int StatisticsMenuIndex = 4;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.MainMenuControler.TournamentSubscriptionButtonClicked += new EventHandler(MenuViews_TournamentSubscriptionClicked);
            this.MainMenuControler.TournamentManagerButtonClicked += new EventHandler(MenuViews_TournamentManagerClicked);
            this.MainMenuControler.GamblingManagerButtonClicked += new EventHandler(MenuViews_GamblingManagerClicked);
            this.MainMenuControler.StatisticsButtonClicked += new EventHandler(MenuViews_StatisticsClicked);
            this.TournamentSubscriptionMenuControler.GoBackButtonClickedBridge += new EventHandler(MenuViews_GoBackButtonClicked);
            this.TournamentManagerMenuControler.GoBackButtonClickedBridge += new EventHandler(MenuViews_GoBackButtonClicked);
            this.GamblingManagerMenuControler.GamblingManagerMenuGoBackButtonClicked += new EventHandler(MenuViews_GoBackButtonClicked);
        }

        private void MenuViews_TournamentSubscriptionClicked(object sender, EventArgs e)
        {
            //TODO: CONSTANTS
            MenuViewsControler.ActiveViewIndex = TournamentSubscriptionMenuIndex;
        }
        private void MenuViews_TournamentManagerClicked(object sender, EventArgs e)
        {
            //TODO: CONSTANTS
            MenuViewsControler.ActiveViewIndex = TournamentManagerMenuIndex;
        }
        private void MenuViews_GamblingManagerClicked(object sender, EventArgs e)
        {
            //TODO: CONSTANTS
            MenuViewsControler.ActiveViewIndex = GamblingManagerMenuIndex;
        }
        private void MenuViews_StatisticsClicked(object sender, EventArgs e) 
        {
            //TODO: CONSTANTS
            MenuViewsControler.ActiveViewIndex = StatisticsMenuIndex;
        }

        private void MenuViews_GoBackButtonClicked(object sender, EventArgs e)
        {
            //TODO: find a better way to do this
            VirtualTournamentsFrontendEvent realEvent = e as VirtualTournamentsFrontendEvent;

            if(realEvent != null)
                if ( realEvent.SenderMenu.Equals("TournamentSubscriptionMenu") ||
                     realEvent.SenderMenu.Equals("TournamentManagerMenu") ||
                     realEvent.SenderMenu.Equals("GamblingManagerMenu") )
                    MenuViewsControler.ActiveViewIndex = MainMenuIndex;
        }
    }
}